-- item_per10floor
-- created by xinj
-- 每前进10层迷宫，获得N个XX

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 进入下层触发触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_USER then
            return 0;
        end

        -- 客户端此时还在前一层，需要+1计算
        local floor = DungeonM.currentLayer() + 1;

        -- 不是在10层，不处理
        if floor % 10 ~= 0 then
            return 0;
        end

        local classId = prop[2];
        if tonumber(prop[2]) > 0 then
            classId = tonumber(prop[2]);
        end

        local ret = FormulaM.invoke("CALC_CAREER_BONUS", who, {1, classId, prop[3]}, 1);
        -- 给奖励
        for _, bonus in pairs(ret) do
            BonusM.doBonus(bonus, "item_per10floor");
        end

        EventMgr.fire(event.LAYER_BONUS_EVENT, { ["bonusList"] = ret, });

        return prop[3];
    end,
    
    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        local num = prop[3];
        local name = ItemM.query(prop[2], "name");

        desc = string.gsub(desc, "{0}", name);
        desc = string.gsub(desc, "{1}", num);

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};
